package com.nuaa.ange.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.nuaa.ange.annotation.ApiLog;
import com.nuaa.ange.common.lang.RespBean;
import com.nuaa.ange.entity.SearchHistory;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @description
 * @author 玦离
 * @date 2023/1/1 18:48
 */

@RestController
@Api(tags = "搜索历史相关接口")
@RequestMapping("/search-history")
public class SearchHistoryController extends BaseController{

    @ApiOperation(value = "得到最新十条搜索记录")
    @GetMapping("/get")
    @ApiLog
    public List<SearchHistory> getSearchHistory() {
        return searchHistoryService.list(new QueryWrapper<SearchHistory>().last("limit 10"));
    }

    @ApiOperation(value = "插入搜索记录")
    @PostMapping("/insert")
    @ApiLog
    public RespBean insertSearchHistory(@RequestBody SearchHistory searchHistory) {
        searchHistoryService.save(searchHistory);
        return RespBean.ok("已记录搜索记录");
    }

    @ApiOperation(value = "删除搜索记录")
    @GetMapping("/delete")
    @ApiLog
    public RespBean deleteSearchHistory(@RequestParam("searchId") int searchId) {
        searchHistoryService.removeById(searchId);
        return RespBean.ok("已删除搜索记录");
    }
}
